#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <copyfile.h>

#include <setoccupier.h>
#include <getoccupier.h>

int main (int argc, const char * argv[]) {
    
/*****************************************************
 * #include <sys/types.h>
 * #include <sys/stat.h>
 * #include <fcntl.h>
 *		int open(char*,int flags,[mode_t mode]);
 *****************************************************/
	/**
#define PERMS 0644
	char * filename = "newfile.test";
	int fd;
	ssize_t nread;
	char buf [1024];
	
	//open file "date" for reading
	fd = open("datetestfile",O_RDONLY);
	if (fd == -1)
		printf("can not open file datetest!\n");
	else
		printf("open file successful!\n");
	//read in the date
	nread = read(fd,buf,1024);
	close(fd);
	 **/
	/**	
	int filedes;
	if((filedes = open(filename,O_RDWR|O_CREAT,PERMS)) == -1)
	{
		printf("count not create %s \n",filename);
		exit(-1);
	}
	else
		printf("create file %s successful.\n",filename);
	
	close(filedes);
	
	exit(0);
	**/
	
/*****************************************************
 * #include <unistd.h>
 *	ssize_t read (int filedes,void *buffer,size_t n);
 *****************************************************/
	/**
#define BUFSIZE 512
	char buffer[BUFSIZE];
	int filedes;
	ssize_t nread;
	long total = 0;
	
	// open anotherfile read only
	if((filedes = open("MAU",O_RDONLY)) == -1)
	{
		printf("error in opening MAU file \n");
		eixt(-1);
	}
	else
		printf("open file successful \n");
	
	// loop until EOF,shown by return value of 0
	
	while((nread = read(filedes,buffer,BUFSIZE)) > 0)
		total += nread;
	printf("total chars in MAU file:%d \n", total);
	
	**/
	
/****************************************************
 * #include <unistd.h>
 *		ssize_t write (int filedes,const void *buffer,size_t n);
 ****************************************************/
	/**
	int ret = copyfile("MAU","MAU.backup");
	**/
	
/****************************************************
 * #include <sys/types.h>
 * #include <unistd.h>
 *		off_t lseek (int filedes, off_t offset, int start_flag);
 ****************************************************/
#define NAMELEN 41
	//char namebuf[NAMELEN] = "Kim4Apple";
		
	//setoccupier( 5,namebuf,NAMELEN);
	char *retname;
    retname = getoccupier( 5);
	printf("%s",retname);
    return 0;
}
